<template>
  <el-pagination
    background
    layout="prev, pager, next"
    :hide-on-single-page="true"
    :page-size=this.$parent.pageSize
    :current-page.sync="currentPage"
    :total=total
    v-on:current-change="changeCurrent(type)"
  >
  </el-pagination>
</template>

<script>
export default {
  name: 'Page',
  data () {
    return {
      total: 0,
      currentPage: 1,
      type: ''
    }
  },
  methods: {
    // 获取分页数据
    showPage (entity, pageNum, pageSize) {
      var that = this
      this.axios({
        url: 'http://localhost:8080/linearAlgebra/' + entity + '/page?pageNum=' + pageNum + '&pageSize=' + pageSize,
        method: 'get',
        contentType: 'application/json'
      }).then(function (response) {
        //  请求的那页为空就返回第一页
        if (response.data.length === 0) {
          that.currentPage = 1
          that.changeCurrent(entity)
        }
        that.$parent.tableData = response.data
      }
      )
    },

    // 获取分页条的数据
    showPagination (entity, pageSize) {
      var datas = this
      this.axios({
        url: 'http://localhost:8080/linearAlgebra/' + entity + '/pageData?' + 'pageSize=' + pageSize,
        method: 'get',
        contentType: 'application/json'
      }).then(function (response) {
        datas.total = response.data.total
      }
      )
    },
    // 改变页面更新数据
    changeCurrent (entity) {
      this.showPage(entity, this.currentPage, this.$parent.pageSize)
    }
  }
}
</script>

<style scoped>
  .el-pagination{
    padding-top: 50px;
    float: right;
  }
</style>
